package demo1105.demo02;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/11/6 16:35
 */
public class Test02 {
    public static void main(String[] args) {
        List<Person> personList = new ArrayList<>();
        personList.add(new Person("欧阳雪",18,"中国",'F'));
        personList.add(new Person("Tom",24,"美国",'M'));
        personList.add(new Person("Harley",22,"英国",'F'));
        personList.add(new Person("向天笑",20,"中国",'M'));
        personList.add(new Person("李康",22,"中国",'M'));
        personList.add(new Person("小梅",20,"中国",'F'));
        personList.add(new Person("何雪",21,"中国",'F'));
        personList.add(new Person("李康2",22,"中国",'M'));

        String[] arr1 = { "a", "b", "c", "d" };
        String[] arr2 = { "d", "e", "f", "g" };
        Stream<String> stream1 = Stream.of(arr1);
        Stream<String> stream2 = Stream.of(arr2);

//        personList.stream().filter(item->item.getAge()>20).forEach(System.out::println);
//
//        personList.stream().map(item->item.getName()).forEach(System.out::println);

//        personList.stream().sorted((o1,o2)->Integer.compare(o2.getAge(),o1.getAge())).forEach(System.out::println);

//        Stream.concat(stream1,stream2).forEach(System.out::println);

//        Stream.concat(stream1,stream2).distinct().forEach(System.out::println);

//        Arrays.stream(arr1).limit(3).forEach(System.out::println);

//        Arrays.stream(arr1).skip(3).forEach(System.out::println);

//        Optional<Person> first = personList.stream().findFirst();
//        System.out.println(first.get());

//        Optional<Person> any = personList.stream().findAny();
//        System.out.println(any.get());

//        boolean b = personList.stream().allMatch(item -> item.getAge() > 18);
//        System.out.println(b);
//
//        boolean b1 = personList.stream().anyMatch(item -> item.getAge() > 18);
//        System.out.println(b1);

//        Optional<Person> max = personList.stream().max((o1, o2) -> o1.getAge() - o2.getAge());
//        System.out.println(max.get());
//
//        long count = personList.stream().count();
//        System.out.println(count);

//        Integer[] arr = {1,2,3};
//        Optional<Integer> reduce = Arrays.stream(arr).reduce((i1, i2) -> i1 *= i2);
//        System.out.println(reduce.get());

//        Long count1 = personList.stream().collect(Collectors.counting());
//        System.out.println(count1);

//        Map<Character, List<Person>> group = personList.stream().collect(Collectors.groupingBy(item -> item.getSex()));
//        System.out.println(group);

//        Double collect = personList.stream().collect(Collectors.averagingInt(item -> item.getAge()));
//        System.out.println(collect);

//        Optional<Person> collect = personList.stream().collect(Collectors.maxBy((o1, o2) -> o1.getAge() - o2.getAge()));
//        System.out.println(collect.get());

//        Integer collect = personList.stream().collect(Collectors.summingInt(item -> item.getAge()));
//        System.out.println(collect);

//        Set<String> collect = personList.stream().map(item -> item.getName()).collect(Collectors.toSet());
//        System.out.println(collect);

//        Map<String, Person> collect = personList.stream().collect(Collectors.toMap(item -> item.getName(), item -> item));
//        System.out.println(collect);

    }

}
